package ecom.beans;

import java.security.NoSuchAlgorithmException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.transaction.UserTransaction;

public class AuthBeanWrapper {
	private AuthBeanInterface AuthBean;
	
	public AuthBeanWrapper() {
		System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.objectweb.carol.jndi.spi.MultiOrbInitialContextFactory");


	    // get JNDI initial context
		Context initialContext = null;
		try {
		    initialContext = new InitialContext();
		} catch (Exception e) {
		    System.err.println("Cannot get initial context for JNDI: " + e);
		    System.exit(2);
		}

	        // We want to start transactions from client: get UserTransaction
	        UserTransaction utx = null;
	        try {
	            utx = (UserTransaction) initialContext.lookup("javax.transaction.UserTransaction");
	        } catch (NamingException e) {
	            System.err.println("Cannot lookup UserTransaction: " + e);
	            System.exit(2);
	        }

	        AuthBean = null;
	        try {
	            AuthBean = (AuthBeanInterface) initialContext
	                    .lookup("ecom.beans.AuthBean" + "_"
	                            + AuthBeanInterface.class.getName() + "@Remote");
	        } catch (NamingException e) {
	            System.err.println("Cannot get AuthBeanInterface : " + e);
	            System.exit(2);
	        }
	}
	
	public boolean authCustomer(String email, String password) throws NoSuchAlgorithmException
	{
		return AuthBean.authCustomer(email, password);
	}
	
}
